package org.shilong.Utility.Loader;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.shilong.ActionItem;
import org.shilong.QuickAction;
import org.shilong.MContext.Json.JSonContext;
import org.shilong.MContext.WebRequest.WebRequestContext;
import org.shilong.Model.CommentModel;
import org.shilong.Model.PartyModel;
import org.shilong.UI.R;
import org.shilong.Utility.GenerateTime;
import org.shilong.Utility.ProgressDialogUtility;
import org.shilong.Utility.SharedPreferenceUtility;
import org.shilong.Utility.ToastUtility;
import org.shilong.ViewUtility.MyAnimationUtils;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

/**
 * 聚会listview 异步加载类
 * 
 * @author cesc
 * 
 */
public class PartyListViewLoader {

	private ListView mListView;

	public final static int NEW_PARTY = 0;

	public final static int HISTORY_PARTY = 1;

	public final static int MY_PARTY = 2;

	private String[] arr;

	private Activity mContext;

	private int loadType;

	public PartyListViewLoader(ListView lv, int loadeType, Activity con) {

		this.mListView = lv;

		this.loadType = loadeType;

		this.mContext = con;

		arr = SharedPreferenceUtility
				.getPersonInfoFromSharedPreference(mContext);
	}

	/**
	 * 开始任务
	 */
	public void startTask() {

		//mHandler.post(new Job(loadType));
		
		JobTask task  = new JobTask(loadType);
		
		task.execute();
	}

	/**
	 * 现在写一个task异步获取数据
	 */
	
	
	private MAdapter mdap = null;

	private class JobTask extends AsyncTask<String, String, String> {

		private int type;

		private List<PartyModel> list;

		public JobTask(int type) {

			this.type = type;

			list = new ArrayList<PartyModel>();

		}

		@Override
		protected String doInBackground(String... params) {

			String rlt = "";
			List<PartyModel> list = new ArrayList<PartyModel>();

			/**
			 * 异步操作
			 */
			switch (type) {
			case NEW_PARTY:

				rlt = WebRequestContext.createInstance(
						WebRequestContext.TYPE_QUERY_ALL_PARIES)
						.getWebRequestRlt("now");

				break;

			case HISTORY_PARTY:

				rlt = WebRequestContext.createInstance(
						WebRequestContext.TYPE_QUERY_ALL_PARIES)
						.getWebRequestRlt("before");

				break;

			case MY_PARTY:

				rlt = WebRequestContext.createInstance(
						WebRequestContext.TYPE_QUERY_MY_PARTY)
						.getWebRequestRlt(arr[2]);

				break;
			default:
				break;
			}

			System.out.println(rlt);

			if (type == HISTORY_PARTY || type == NEW_PARTY) // 获取历史聚会和新建聚会
				list = (List<PartyModel>) JSonContext.createInstance(
						JSonContext.TYPE_GET_PARIES).getJsonRlt(rlt);

			if (type == MY_PARTY) // 获取我的聚会
				list = (List<PartyModel>) JSonContext.createInstance(
						JSonContext.TYPE_GET_MY_PARIES).getJsonRlt(rlt);

			

			if (type == HISTORY_PARTY)
				mdap = new MAdapter(list, 1);

			if (type == NEW_PARTY)
				mdap = new MAdapter(list, 0);

			if (type == MY_PARTY)
				mdap = new MAdapter(list, 2);

			
			
			
			

			return null;
		}

		@Override
		protected void onPostExecute(String result) {

			mListView.setAdapter(mdap);

		}

	}

	private Handler mHandler = new Handler();

	private class Job implements Runnable {

		private int type;

		public Job(int mType) {
			this.type = mType;
		}

		@Override
		public void run() {

			String rlt = "";
			List<PartyModel> list = new ArrayList<PartyModel>();

			/**
			 * 异步操作
			 */
			switch (type) {
			case NEW_PARTY:

				rlt = WebRequestContext.createInstance(
						WebRequestContext.TYPE_QUERY_ALL_PARIES)
						.getWebRequestRlt("now");

				break;

			case HISTORY_PARTY:

				rlt = WebRequestContext.createInstance(
						WebRequestContext.TYPE_QUERY_ALL_PARIES)
						.getWebRequestRlt("before");

				break;

			case MY_PARTY:

				rlt = WebRequestContext.createInstance(
						WebRequestContext.TYPE_QUERY_MY_PARTY)
						.getWebRequestRlt(arr[2]);

				break;
			default:
				break;
			}

			System.out.println(rlt);

			if (type == HISTORY_PARTY || type == NEW_PARTY) // 获取历史聚会和新建聚会
				list = (List<PartyModel>) JSonContext.createInstance(
						JSonContext.TYPE_GET_PARIES).getJsonRlt(rlt);

			if (type == MY_PARTY) // 获取我的聚会
				list = (List<PartyModel>) JSonContext.createInstance(
						JSonContext.TYPE_GET_MY_PARIES).getJsonRlt(rlt);

			MAdapter adp = null;

			if (type == HISTORY_PARTY)
				adp = new MAdapter(list, 1);

			if (type == NEW_PARTY)
				adp = new MAdapter(list, 0);

			if (type == MY_PARTY)
				adp = new MAdapter(list, 2);

			mListView.setAdapter(adp);

		}

	}

	private class MAdapter extends BaseAdapter {

		private List<PartyModel> mlist;

		private int type;

		public MAdapter(List<PartyModel> ll, int type) {

			this.mlist = ll;

			this.type = type;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mlist.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return mlist.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			// TODO Auto-generated method stub

			View root = null;

			if (type == 0)
				root = getNewPartyView(mlist.get(arg0)); // 0为 新聚会

			if (type == 1)
				root = getHistoryPartyView(mlist.get(arg0)); // 1为 历史聚会

			if (type == 2)
				root = getMyPartyView(mlist.get(arg0));// 2为我的聚会

			return root;
		}

	}

	/**
	 * 我的聚会View
	 * 
	 * @param model
	 * @return
	 */
	private View getMyPartyView(final PartyModel model) {

		final View loca = mContext
				.findViewById(R.id.new_layout_show_history_paries_content_outter_layout);

		LayoutInflater in = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View root = in.inflate(R.layout.new_inner_party_listview_item, null);

		TextView title = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_name);
		TextView time = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_time);
		TextView person = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_start_person);

		String me_tpe = "";

		if (model.getPa_type().equals("fq"))
			me_tpe = "-->发起的";

		if (model.getPa_type().equals("cy"))
			me_tpe = "-->参与的";

		title.setText(model.getPa_title());
		time.setText(model.getPa_start_time());
		person.setText("我" + me_tpe);

		root.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				quickActionMenuForMyParty(v, model, loca);

			}
		});

		return root;

	}

	private void quickActionMenuForMyParty(View v, final PartyModel model,
			final View loca) {

		ActionItem openAction = new ActionItem();
		openAction.setTitle("参与人");
		openAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.pl_img));
		ActionItem callAction = new ActionItem();
		callAction.setTitle("评论");
		callAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.cj_img));

		ActionItem commentAction = new ActionItem();
		commentAction.setTitle("查看评论");
		commentAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.cj_img));

		final QuickAction mQuickAction = new QuickAction(mContext);

		if (model.getPa_type().equals("fq"))
			mQuickAction.addActionItem(openAction);

		mQuickAction.addActionItem(callAction);
		mQuickAction.addActionItem(commentAction);
		mQuickAction
				.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
					@Override
					public void onItemClick(int pos) {

						if (model.getPa_type().equals("fq")) {

							switch (pos) {

							case 0:

								myPopWindow.dismiss();

								addPeopleLogic(model, loca);

								break;
							case 1:
								commnetLogic(model, loca);

								break;
							case 2:

								queryComment(model, loca);

								break;
							default:
								break;
							}

						}

						if (model.getPa_type().equals("cy")) {

							switch (pos) {

							case 0:
								myPopWindow.dismiss();
								commnetLogic(model, loca);

								break;
							case 1:

								myPopWindow.dismiss();
								queryComment(model, loca);

								break;
							default:
								break;
							}

						}

					}
				});
		mQuickAction.show(v);
	}

	/**
	 * 获取新聚会的View 新聚会的逻辑中有详情和参加
	 * 
	 * @param location
	 * @param mList
	 * @return
	 */
	private View getNewPartyView(final PartyModel model) {

		final View loca = mContext
				.findViewById(R.id.new_layout_show_history_paries_content_outter_layout);

		LayoutInflater in = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View root = in.inflate(R.layout.new_inner_party_listview_item, null);

		TextView title = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_name);
		TextView time = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_time);
		TextView person = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_start_person);

		title.setText(model.getPa_title());
		time.setText(model.getPa_start_time());
		person.setText(model.getAccount_name());

		root.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				quickActionMenuForNewParty(v, model, loca);

			}
		});

		return root;

	}

	/**
	 * 获取历史聚会的view
	 * 
	 * @param model
	 * @return
	 */
	View getHistoryPartyView(final PartyModel model) {
		final View loca = mContext
				.findViewById(R.id.new_layout_show_history_paries_content_outter_layout);

		LayoutInflater in = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View root = in.inflate(R.layout.new_inner_party_listview_item, null);

		TextView title = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_name);
		TextView time = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_time);
		TextView person = (TextView) root
				.findViewById(R.id.brand_party_listview_item_party_start_person);

		title.setText(model.getPa_title());
		time.setText(model.getPa_start_time());
		person.setText(model.getAccount_name());

		root.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				quickActionMenuForHistoryParty(v, model, loca);

			}
		});

		return root;
	}

	public static PopupWindow myPopWindow;

	/**
	 * 启动快速链接--新聚会
	 * 
	 * @param v
	 */
	private void quickActionMenuForNewParty(View v, final PartyModel model,
			final View loca) {

		ActionItem openAction = new ActionItem();
		openAction.setTitle("详情");
		openAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.pl_img));
		ActionItem callAction = new ActionItem();
		callAction.setTitle("参加");
		callAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.cj_img));
		ActionItem commentAction = new ActionItem();
		commentAction.setTitle("查看评论");
		commentAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.cj_img));

		final QuickAction mQuickAction = new QuickAction(mContext);
		mQuickAction.addActionItem(openAction);
		mQuickAction.addActionItem(callAction);
		mQuickAction.addActionItem(commentAction);
		mQuickAction
				.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
					@Override
					public void onItemClick(int pos) {
						switch (pos) {
						case 0:

							checkDetailLogic(model, loca);

							break;
						case 1:

							takePartInLogic(model);
							break;

						case 2:

							queryComment(model, loca);

							break;
						default:
							break;
						}
					}
				});
		mQuickAction.show(v);
	}

	/**
	 * 启动快速链接--历史聚会
	 * 
	 * @param v
	 */
	private void quickActionMenuForHistoryParty(View v, final PartyModel model,
			final View loca) {

		ActionItem openAction = new ActionItem();
		openAction.setTitle("详情");
		openAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.in_img));
		ActionItem callAction = new ActionItem();
		callAction.setTitle("评论");
		callAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.pl_img));
		ActionItem commentAction = new ActionItem();
		commentAction.setTitle("查看评论");
		commentAction.setIcon(mContext.getResources().getDrawable(
				R.drawable.cj_img));

		final QuickAction mQuickAction = new QuickAction(mContext);
		mQuickAction.addActionItem(openAction);
		mQuickAction.addActionItem(callAction);
		mQuickAction.addActionItem(commentAction);
		mQuickAction
				.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
					@Override
					public void onItemClick(int pos) {
						switch (pos) {
						case 0:
							checkDetailLogic(model, loca);
							break;
						case 1:
							commnetLogic(model, loca);
							break;
						case 2:
							queryComment(model, loca);
							break;
						default:
							break;
						}
					}
				});
		mQuickAction.show(v);
	}

	/**
	 * 查看细节逻辑
	 */
	private void checkDetailLogic(PartyModel model, View loca) {

		myPopWindow = null;

		myPopWindow = new PopupWindow(mContext);

		myPopWindow.setFocusable(true);
		myPopWindow.setOutsideTouchable(true);
		myPopWindow.setTouchable(true);

		int width = loca.getWidth();
		int height = loca.getHeight();

		LayoutInflater inlater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View root = inlater.inflate(R.layout.layout_party_detail_content, null);

		myPopWindow.setBackgroundDrawable(mContext.getResources().getDrawable(
				R.drawable.body_bg_img));

		myPopWindow.setWidth(width - 20);
		myPopWindow.setHeight(height);

		myPopWindow.setAnimationStyle(R.style.MyPopWindow);

		myPopWindow.setContentView(root);

		myPopWindow.showAtLocation(loca, Gravity.CENTER
				| Gravity.CENTER_HORIZONTAL, 0, 0);

		myPopWindow.setTouchInterceptor(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View arg0, MotionEvent event) {
				// TODO Auto-generated method stub

				if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {

					myPopWindow.dismiss();
					return true;
				}
				return false;
			}
		});

		initDetailPopupWindowComponents(root, model);

	}

	/**
	 * 参加聚会逻辑
	 */
	private void takePartInLogic(PartyModel model) {
		System.out.println("参加聚会...");
		TakePartInPartyTask task = new TakePartInPartyTask();
		task.execute("123", model.getPa_seq_id());

	}

	/**
	 * 初始化查看信息弹出框
	 * 
	 * @param root
	 * @param model
	 */
	private void initDetailPopupWindowComponents(View root,
			final PartyModel model) {

		System.out.println("评论 /参与人是:" + model.getPa_comment());
		final ImageView closeButtonImageView = (ImageView) root
				.findViewById(R.id.close_button_cross_imageview);

		closeButtonImageView.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				MyAnimationUtils.closeLayout(closeButtonImageView, mContext,
						myPopWindow);

			}
		});

		final EditText party_input_title = (EditText) root
				.findViewById(R.id.party_input_title);

		final EditText party_input_content = (EditText) root
				.findViewById(R.id.party_input_content);

		final TextView party_pure_show_time_textview = (TextView) root
				.findViewById(R.id.party_pure_show_time_textview);

		party_input_title.setText(model.getPa_title());

		party_input_content.setText(model.getPa_comment());

		party_pure_show_time_textview.setText("[" + model.getPa_start_time()
				+ "--" + model.getEnd_time() + "]");

	}

	/**
	 * 查询评论
	 * @param model
	 * @param loca
	 */
	private void queryComment(PartyModel model, View loca) {

		myPopWindow = null;

		myPopWindow = new PopupWindow(mContext);

		myPopWindow.setFocusable(true);
		myPopWindow.setOutsideTouchable(true);
		myPopWindow.setTouchable(true);

		int width = loca.getWidth();
		int height = loca.getHeight();

		LayoutInflater inlater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View root = inlater.inflate(R.layout.include_comment_layout, null);

		myPopWindow.setBackgroundDrawable(mContext.getResources().getDrawable(
				R.drawable.body_bg_img));

		myPopWindow.setWidth(width - 20);
		myPopWindow.setHeight(height);

		myPopWindow.setAnimationStyle(R.style.MyPopWindow);

		myPopWindow.setContentView(root);

		myPopWindow.showAtLocation(loca, Gravity.CENTER
				| Gravity.CENTER_HORIZONTAL, 0, 0);

		myPopWindow.setTouchInterceptor(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View arg0, MotionEvent event) {
				// TODO Auto-generated method stub

				if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {

					myPopWindow.dismiss();
					return true;
				}
				return false;
			}
		});

		initQueryCommentsPopupWindowComponents(root, model);
	}

	private void initQueryCommentsPopupWindowComponents(View root,
			final PartyModel model) {

		final ListView show_comment_listview = (ListView) root
				.findViewById(R.id.show_comment_listview);

		Handler handler = new Handler();

		handler.post(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				ToastUtility.showToast(mContext, "开始获取聚会信息");

				String rlt = "";
				rlt = WebRequestContext.createInstance(
						WebRequestContext.TYPE_QUERY_COMMENT_Party)
						.getWebRequestRlt(model.getPa_seq_id());

				List<CommentModel> mlist = new ArrayList<CommentModel>();
				try {
					JSONObject obj = new JSONObject(rlt);

					JSONArray arr = obj.getJSONArray("rlt");

					for (int i = 0; i < arr.length(); i++) {

						CommentModel model = new CommentModel();

						JSONObject oo = arr.getJSONObject(i);

						model.setAccount_name(oo.getString("account_name"));

						model.setComment(oo.getString("comment"));
						model.setTime(oo.getString("comment_time"));

						mlist.add(model);

					}

					if (mlist == null || mlist.size() == 0) {

						ToastUtility.showToast(mContext, "暂无评论..");

						myPopWindow.dismiss();
					} else {

						MyAdapter2 ap2 = new MyAdapter2(mlist);

						show_comment_listview.setAdapter(ap2);
					}

				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		});

		final ImageView closeButtonImageView = (ImageView) root
				.findViewById(R.id.close_button_cross_imageview);

		closeButtonImageView.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				MyAnimationUtils.closeLayout(closeButtonImageView, mContext,
						myPopWindow);

			}
		});
		
	}

	/**
	 * 添加聚会参加人
	 * 
	 * @param model
	 * @param loca
	 */
	private void addPeopleLogic(PartyModel model, View loca) {

		myPopWindow = null;

		myPopWindow = new PopupWindow(mContext);

		myPopWindow.setFocusable(true);
		myPopWindow.setOutsideTouchable(true);
		myPopWindow.setTouchable(true);

		int width = loca.getWidth();
		int height = loca.getHeight();

		LayoutInflater inlater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View root = inlater
				.inflate(R.layout.layout_comment_party_content, null);

		myPopWindow.setBackgroundDrawable(mContext.getResources().getDrawable(
				R.drawable.common_popwindow));

		myPopWindow.setWidth(width - 20);
		myPopWindow.setHeight(height);

		myPopWindow.setAnimationStyle(R.style.MyPopWindow);

		myPopWindow.setContentView(root);

		myPopWindow.showAtLocation(loca, Gravity.CENTER
				| Gravity.CENTER_HORIZONTAL, 0, 0);

		initCanyuPopupWindowComponents(root, model);

	}

	/**
	 * 添加 参与人布局初始化
	 * 
	 * @param root
	 * @param model
	 */
	private void initCanyuPopupWindowComponents(View root,
			final PartyModel model) {
		final EditText party_input_title = (EditText) root
				.findViewById(R.id.party_input_title);

		final EditText party_input_content = (EditText) root
				.findViewById(R.id.party_input_content);

		final ImageView closeButtonImageView = (ImageView) root
				.findViewById(R.id.close_button_cross_imageview);

		party_input_title.setText(model.getPa_title());

		closeButtonImageView.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				MyAnimationUtils.closeLayout(closeButtonImageView, mContext,
						myPopWindow);

			}
		});

		final Button yesButton = (Button) root
				.findViewById(R.id.comment_yes_button);

		yesButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				AddPeopleTask task = new AddPeopleTask();
				task.execute(arr[2], model.getPa_seq_id(), party_input_content
						.getText().toString());

			}
		});

		final Button noButton = (Button) root
				.findViewById(R.id.comment_no_button);

		noButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub

				System.out.println("关闭");
				myPopWindow.dismiss();

			}
		});

	}

	/**
	 * 评论逻辑
	 */
	private void commnetLogic(PartyModel model, View loca) {

		myPopWindow = null;

		myPopWindow = new PopupWindow(mContext);

		myPopWindow.setFocusable(true);
		myPopWindow.setOutsideTouchable(true);
		myPopWindow.setTouchable(true);

		int width = loca.getWidth();
		int height = loca.getHeight();

		LayoutInflater inlater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View root = inlater
				.inflate(R.layout.layout_comment_party_content, null);

		myPopWindow.setBackgroundDrawable(mContext.getResources().getDrawable(
				R.drawable.common_popwindow));

		myPopWindow.setWidth(width - 20);
		myPopWindow.setHeight(height);

		myPopWindow.setAnimationStyle(R.style.MyPopWindow);

		myPopWindow.setContentView(root);

		myPopWindow.showAtLocation(loca, Gravity.CENTER
				| Gravity.CENTER_HORIZONTAL, 0, 0);

		initCommentPopupWindowComponents(root, model);

	}

	/**
	 * 初始化评论弹出框控件
	 * 
	 * @param root
	 */
	private void initCommentPopupWindowComponents(View root,
			final PartyModel model) {

		TextView title = (TextView) root
				.findViewById(R.id.content_title_textview);
		title.setText("评论内容");

		final EditText party_input_title = (EditText) root
				.findViewById(R.id.party_input_title);

		final EditText party_input_content = (EditText) root
				.findViewById(R.id.party_input_content);

		final ImageView closeButtonImageView = (ImageView) root
				.findViewById(R.id.close_button_cross_imageview);

		party_input_title.setText(model.getPa_title());

		closeButtonImageView.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				MyAnimationUtils.closeLayout(closeButtonImageView, mContext,
						myPopWindow);

			}
		});

		final Button yesButton = (Button) root
				.findViewById(R.id.comment_yes_button);

		yesButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				System.out.println("party_input_content:" + party_input_content.getText().toString());
				
				CommentTask task = new CommentTask();
				task.execute(arr[2], model.getPa_seq_id(), party_input_content
						.getText().toString(), GenerateTime.getCurrentTime());

			}
		});

		final Button noButton = (Button) root
				.findViewById(R.id.comment_no_button);

		noButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub

				System.out.println("关闭");
				myPopWindow.dismiss();

			}
		});

	}

	/**
	 * 评论异步任务
	 * 
	 * @author cesc
	 * 
	 */
	private class CommentTask extends AsyncTask<String, String, String> {

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub

			System.out.println("评论的返回结果是：" + result);
			ProgressDialogUtility.cancelDialog();

			if (result.equals("comment_successed")) {

				ToastUtility.showToast(mContext, "评论成功");

				myPopWindow.dismiss();

			} else if (result.equals("comment_failed")) {

				ToastUtility.showToast(mContext, "评论失败,服务器有点不给力了");

			} else {

				ToastUtility.showToast(mContext, "评论失败,亲你的网开了吗？");
			}

			super.onPostExecute(result);
		}

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			ProgressDialogUtility.showDialog(mContext, "评论中..");
			super.onPreExecute();
		}

		@Override
		protected String doInBackground(String... arg0) {
			// TODO Auto-generated method stub

			String rlt = "nodatas";
			rlt = WebRequestContext.createInstance(
					WebRequestContext.TYPE_COMMENT_PARTY)
					.getWebRequestRlt(arg0);

			return rlt;
		}

	}

	/**
	 * 添加参与人的task
	 * 
	 * @author cesc
	 * 
	 */
	private class AddPeopleTask extends AsyncTask<String, String, String> {

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub

			System.out.println("评论的返回结果是：" + result);
			ProgressDialogUtility.cancelDialog();

			if (result.equals("add_successfully")) {

				ToastUtility.showToast(mContext, "添加成功");

				myPopWindow.dismiss();

			} else {

				ToastUtility.showToast(mContext, "添加失败,服务器有点不给力了");

			}
			super.onPostExecute(result);
		}

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			ProgressDialogUtility.showDialog(mContext, "添加中..");
			super.onPreExecute();
		}

		@Override
		protected String doInBackground(String... arg0) {
			// TODO Auto-generated method stub

			String rlt = "nodatas";
			rlt = WebRequestContext.createInstance(
					WebRequestContext.TYPE_ADD_PEOPEL_TAKE_PART_IN_PARTY)
					.getWebRequestRlt(arg0);

			return rlt;
		}

	}

	/**
	 * 参加聚会的实现类
	 * 
	 * @author cesc
	 * 
	 */
	private class TakePartInPartyTask extends AsyncTask<String, String, String> {

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub

			if (result.equals("take_part_in_party_successed")) {

				ToastUtility.showToast(mContext, "加入聚会成功，等待参加聚会吧!");

			} else {

				ToastUtility.showToast(mContext, "加入聚会失败");

			}

			ProgressDialogUtility.cancelDialog();
			super.onPostExecute(result);
		}

		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			ProgressDialogUtility.showDialog(mContext, "加入聚会中..");
			super.onPreExecute();
		}

		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
			String rlt = "";

			rlt = WebRequestContext.createInstance(
					WebRequestContext.TYPE_TAKE_PART_IN_PARTY)
					.getWebRequestRlt(params);
			System.out.println("加入聚会的请求值是:" + rlt);
			return rlt;
		}

	}

	private class MyAdapter2 extends BaseAdapter {
		private List<CommentModel> ll;

		public MyAdapter2(List<CommentModel> ll) {

			this.ll = ll;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return ll.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return ll.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			// TODO Auto-generated method stub\

			LayoutInflater inf = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			View rr = inf.inflate(R.layout.inner_show_comment_layout, null);

			TextView time = (TextView) rr
					.findViewById(R.id.item_comment_time_textview);
			;
			TextView name = (TextView) rr
					.findViewById(R.id.item_comment_name_textview);
			;
			TextView comment = (TextView) rr
					.findViewById(R.id.item_comment_textview);

			time.setText(ll.get(arg0).getTime());
			name.setText(ll.get(arg0).getAccount_name());
			comment.setText(ll.get(arg0).getComment());

			return rr;
		}

	}
}
